package com.stx.servlet.visitor;

import com.stx.bean.Car;
import com.stx.bean.Visitor;
import com.stx.mapper.VisitorMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/*添加访客信息*/
@WebServlet(urlPatterns = {"/visitorAdd"})
public class VisitorAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id= UUID.randomUUID().toString();      //获取用户uuid
        String name = req.getParameter("name");
        String visiteWho = req.getParameter("visiteWho");
        String phone = req.getParameter("phone");
        String idCard = req.getParameter("idCard");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   //获取当前时间
        String date = sdf.format(new Date());
        Visitor visitor = new Visitor(id, name, visiteWho, phone, idCard, date);
        try {
            Boolean aBoolean = VisitorMapper.visitorAdd(visitor);
            resp.sendRedirect("/visitorList");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
